package cn.org.xwb.main.controller;

import cn.org.xwb.main.dto.BaseRespResult;
import cn.org.xwb.main.service.RsaService;
import cn.org.xwb.main.utils.HttpUtil;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpRequest;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * RSA 相关的控制器
 */
@RestController
@RequestMapping("/rsa")
@Log4j2
public class RSAController {

    @Autowired
    private RsaService rsaService;

    /**
     * 向客户端发送通用的 RSA 公钥
     *
     * @return 响应信息对象
     */
    @GetMapping("/common/public")
    public BaseRespResult<Object> sendRsaCommonPublicKey(HttpServletRequest request) {
        log.info("客户端 {} 正在获取通用的 RSA 公钥", HttpUtil.getClientHostIpPort(request));
        return rsaService.sendRsaCommonPublicKey(request);
    }

}
